package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.DocumentService;
import com.yixun.qfbao.apidto.GetFilesReqDto;
import com.yixun.qfbao.apidto.GetFilesResDto;
import com.yixun.qfbao.config.FileConfig;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.GetFilesReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 获取附件
 * @author guifang.weng
 * @create 2017-11-23 17:43
 **/
@Service
public class GetFilesHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetFilesHander.class);

    @Autowired
    private DocumentService documentService;
    @Autowired
    private FileConfig fileConfig;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetFilesResDto> res = new BaseResponseDTO<>();
        GetFilesReqVo reqVo = (GetFilesReqVo)reqDto;
        GetFilesReqDto getFilesReqDto = reqVo.getParams();
        getFilesReqDto.setFileGet(fileConfig.getFileGet());
        try {
            GetFilesResDto resDto = documentService.getFile(getFilesReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (Exception e) {
            logger.error("GetFilesHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("获取附件失败");
        }
        return res;
    }
}
